package com.example.demo.controller;

import com.example.demo.model.Role1;
import com.example.demo.service.RoleService1;
import com.example.demo.tool.ResponseMessage;
import com.example.demo.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 编写者：施皓
 * 编写时间：2019.5.26
 */
@RestController(value = "/Role1")
public class RoleController1 {

    @Autowired
    private RoleService1 roleService;

    @RequestMapping(value = "/getStr1")
    public String getStr(String str){
        return "你输入的名字叫" + str;

    }
    @CrossOrigin
    @RequestMapping(value = "/getOne1")
    public Role1 getOne(Integer rid){
        return roleService.selectByPrimaryKey(rid);
    }

    @CrossOrigin//解决跨越问题
    @RequestMapping(value = "getIsBegin1")
    public List<Role1> getIsBegin(){
        System.out.println("调用角色全部类型的接口");
        List<Role1> listRole = roleService.getIsBegin();
        return listRole;
    }

    @CrossOrigin
    @RequestMapping(value = "getAll1")
    public ResponseMessage getAll(){
        List<Role1> listRole = roleService.getAll();
        System.out.println("调用角色全部信息的方法");
        Map<String,List> map = new HashMap<>();
        map.put("list",roleService.getAll());
        return Result.success("200",map);
    }
    @CrossOrigin
    @RequestMapping(value = "/delRole1",method =  RequestMethod.GET)
    public int delRole(Integer rid){
        return roleService.delRole(rid);
    }

    @CrossOrigin
        @RequestMapping(value = "/addRole1",method = RequestMethod.PUT)
    public int addRole(@RequestBody Role1 rolemodel){
        //判断传入数据是否为空
        if (rolemodel!=null){

        }else {

        }
        return roleService.insertRole(rolemodel);
    }
@CrossOrigin
    @RequestMapping(value = "/updateRole1",method = RequestMethod.PUT)
    public  int updateRole(@RequestBody Role1 rolemodel){
        if (rolemodel!=null){

        }else {

            System.out.println("请输入数据");
        }
        return roleService.updateRole(rolemodel);
    }

}
